package de.mp3player.repository;

import java.io.*;

import de.mp3player.objects.Playlist;

public class IOPlaylist {
	private InputStream input = null;
	private OutputStream out = null;
	private Playlist playlist = null;
	private String filename;
	
	public IOPlaylist(String filename){
		this.filename = filename;
	}
	
	public void readPlaylist(){
		try{
			input = new FileInputStream(filename);
			ObjectInputStream o = new ObjectInputStream(input);
			playlist = (Playlist) o.readObject();
		} catch (IOException e){ILogger.logger.info("Datei nicht gefunden");
		} catch (ClassNotFoundException e){ILogger.logger.info("Klasse nicht gefunden");}
		finally {
			try{
				input.close();
			} catch (Exception e){;}
		}
	}
	public void writeMap(){
		try{
			out = new FileOutputStream(filename);
			ObjectOutputStream o = new ObjectOutputStream(out);
			o.writeObject(playlist);
		} catch (IOException e){ILogger.logger.info("Schreib Fehler in Datei");}
		finally{
			try{
				out.close();
			} catch (Exception e){;}
		}
	}
}
